﻿@using ECGadmin.Common
@using ECGadmin.WebUI.Models
@using ECGadmin.WebUI.CustomHelpers
@model NewsDto
@{
    ViewBag.Title = "EditNews";
    Layout = "~/Views/Shared/_layout.cshtml";
}
<nav>
    <div id="jCrumbs" class="breadCrumb module">
        <ul>
            <li><a href="@Url.Action("Index", "Home")"><i class="bootstrap icon-home"></i></a></li>
            <li><a href="javascript:void(0)">Sản phẩm</a> </li>
            <li><a href="@Url.Action("Index", "News")">Danh sách tin</a> </li>
            <li><a href="@Url.Action("EditNews", "News")">Thêm tin</a> </li>
        </ul>
    </div>
</nav>
<div class="toolBox">
    @Html.ToolBox(new List<object> { new Save() { ClassCss = "Save", ActionName = "Javascript:void(0)" }, new Delete() { ClassCss = "Del", ActionName = "DelCategory" }, new Back { ClassCss = "Back", ActionName = @Url.Action("Index", "News") } })
</div>
<div class="box-Info">
    <div class="Info-header">
        <span>Thêm mới danh mục </span>
    </div>
    <div class="Info-body">
        @using (Html.BeginForm("EditNews", "News", FormMethod.Post, new { @class = "formEditNews", enctype = "multipart/form-data" }))
        {
            <table cellpadding="0" cellspacing="0" width="100%" border="0" class="table-info">
                <tr>
                    <td class="tInfoLeft">Tiêu đề 
                    </td>
                    <td class="tInfoRight">
                        @Html.TextBoxFor(m => m.Title)
                        @Html.ValidationMessageFor(m => m.Title)
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Danh mục cha
                    </td>
                    <td class="tInfoRight">
                        @Html.DropDownListFor(m => m.CategoryId, new SelectList(((List<NewsCategoryDto>)(ViewBag.ParentList)) ?? new List<NewsCategoryDto>(), "Id", "CateName"))
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Mô tả ngắn
                    </td>
                    <td class="tInfoRight">
                        @Html.TextAreaFor(m => m.Summary, new { @class = "texareaCss" })
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Nội dung
                    </td>
                    <td class="tInfoRight">
                        <textarea class="ckeditor" rows="50" cols="60" id="editor1" name="Description">@Model.Description</textarea>
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Ảnh đại diện
                    </td>
                    <td class="tInfoRight">
                        <input type="file" name="imageFile" />
                        @Html.HiddenFor(m => m.ImagePath)
                        @Html.HiddenFor(m => m.CreateDate)
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Meta title
                    </td>
                    <td class="tInfoRight">
                        @Html.TextBoxFor(m => m.MetaTitle, new { @onkeyup = "countTextAreaChar(this, 70,'countNewsMetaTitle')" })<br />
                        <input readonly="readonly" class="cssInputHidden" type="text" name="countNewsMetaTitle" size="3" maxlength="3" style="width: 53px; height: 23px; margin: 0px; padding: 0px 0px 0px 10px;" value="0">
                        ký tự. Hầu hết các công cụ tìm kiếm sử dụng tối đa <span style="color: red;">70</span> ký tự cho tiêu đề
                    </td>
                </tr>

                <tr>
                    <td class="tInfoLeft">Meta description
                    </td>
                    <td class="tInfoRight">
                        @Html.TextAreaFor(m => m.MetaDescription, new { @class = "texareaCss", @onkeyup = "countTextAreaChar(this, 160,'countNewsMetaDesc')" })
                        <br />
                        <input readonly="readonly" class="cssInputHidden" type="text" name="countNewsMetaDesc" size="3" maxlength="3" style="width: 53px; height: 23px; margin: 0px; padding: 0px 0px 0px 10px;" value="0">
                        ký tự. Hầu hết các công cụ tìm kiếm sử dụng tối đa <span style="color: red;">160</span> ký tự cho các mô tả
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Meta keyword
                    </td>
                    <td class="tInfoRight">
                        @Html.TextAreaFor(m => m.MetaKeyword, new { @class = "texareaCss" })
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Tags
                    </td>
                    <td class="tInfoRight">
                        <input type="text" style="width: 250px!important;" value="" id="txtTagAdd"/>
                        <input type="button" value="Add" style="width: 40px;" id="btnAddTags"/>
                        <input type="hidden" name="NameTag" value=""/>
                        <div class="tagchecklist clearfix">
                            @Html.Action("ShowTag", "News",new {newsId = Model.Id})
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Nổi bật
                    </td>
                    <td class="tInfoRight">
                        @Html.CheckBoxFor(m => m.Hot, new { @checked = "checked" })
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">Kích hoạt
                    </td>
                    <td class="tInfoRight">
                        @Html.CheckBoxFor(m => m.Active, new { @checked = "checked" })
                    </td>
                </tr>
            </table>
        }
    </div>
</div>

@section scripts
{
    @Scripts.Render("~/bundles/jqueryval")
    <script src="@Url.Content("~/Scripts/WYSIWYG/ckeditor/ckeditor.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/WYSIWYG/ckfinder/ckfinder.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var editor = CKEDITOR.replace('editor1');
        CKFinder.setupCKEditor(editor, '/Scripts/WYSIWYG/ckfinder/');
    </script>
    <script>
        SubmitFormUseToolBox($('ul li.Save a'), $('form'));
        
        /* TAG
        ---------------------------------------------------------------------------
        */

        //Enter
        $("#txtTagAdd").keypress(function (e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13) { //Enter keycode
                //Them tag vao box
                AddTags($(this), $('div.tagchecklist'), $('input[name=NameTag]'));
            }
        });
        
        $('#btnAddTags').click(function () {
            AddTags($('#txtTagAdd'), $('div.tagchecklist'), $('input[name=NameTag]'));
        });

        function AddTags(cmdVal, plc, hid) {
            var val = cmdVal.val();
            //val: chuoi gia tri
            //plc: ket qua tra ve
            if (cmdVal != undefined && val != '') {
                var listTag = val.split(',');
                if (listTag.length) {
                    for (var i = 0; i < listTag.length; i++) {
                        var str = '<span><a id="post_tag" class="ntdelbutton"></a>&nbsp;' + $.trim(listTag[i]) + '</span>';
                        plc.append(str);
                    }
                    // them vao hiden nametag
                    var hidVal = '';
                    var seen = {};
                    plc.children('span').each(function () {
                        var txt = $(this).text();
                        //Loai bo trung lap
                        if (seen[txt]) {
                            $(this).remove();
                        }
                        else {
                            seen[txt] = true;
                            //noi lai cac text: giang,hoang,ngo
                            hidVal += $.trim(txt) + ',';
                        }
                    });
                    hid.val(hidVal.substring(0, hidVal.length - 1));
                    cmdVal.val('');
                }
            } else {
                //alert('value is empty');
            }

            DelTag();//call del tag
        }


        DelTag();//call del tag first
        function DelTag() {
            //Xoa tag
            $('.ntdelbutton').click(function () {
                var parent = $(this).parent();
                parent.remove(); //del
                callbackTag(); //luu lai cac tag khi xoa
            });
        }

        callbackTag();//luu cac tag da co khi bat dau load
        function callbackTag() {
            // them vao hiden nametag
            var hidVal = '';
            var seen = {};
            $('div.tagchecklist').children('span').each(function () {
                var txt = $(this).text();
                //Loai bo trung lap
                if (seen[txt]) {
                    $(this).remove();
                }
                else {
                    seen[txt] = true;
                    //noi lai cac text: giang,hoang,ngo
                    hidVal += $.trim(txt) + ',';
                }
            });
            $('input[name=NameTag]').val(hidVal.substring(0, hidVal.length - 1));
        }
        /* END TAG
       ---------------------------------------------------------------------------
       */
    </script>
}

